function check_or_submit(e){
    var err = 0;
    
    $('span > span > div').hide();
    //check for password
    if ($('#password').val() != $('#password1').val()) {
       $('div#pwddifferent').show() ;
       err = 1;
    }

    //check for email
    if ($('#email').val().length == 0) {
        $('div#emailempty').show();
        err = 1;
    }
    $.ajax({
            url : '/user/check?email='+$('#email').val(),
            error : function(xhr) {
                alert('Ajax breaks as an error has occurred');
            },
            success : function(response) {
                if (response.length > 4) {
                    $('div#emailinvalid').show();
                    err = 1;
                }
            }
        });

    return !err;
}
                
$(document).ready(function(e){
        $('span > span > div').hide();
        $('#form').submit(check_or_submit);
    });
